package com.stockz.ui.swing.watchlist.widget;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stockz.ui.swing.widget.JButton;
import com.stockz.watchlist.manager.WatchListManager;
import com.stockz.watchlist.model.WatchList;

@Component
public class RemoveWatchListActionListener implements ActionListener {

	@Autowired
	private WatchListManager watchListManager;
	private RemoveWatchListFromUICallback callback;
	
	public void setCallback(RemoveWatchListFromUICallback callback) {
		this.callback = callback;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		JButton button = (JButton)e.getSource();
		WatchList watchList = (WatchList)button.getPayload();
		
		watchListManager.remove(watchList.getId());
		if(callback != null){
			callback.removeFromUI(watchList);
		}
	}

}
